﻿using System;
using System.Diagnostics;

namespace CI.MesopotamiaScrnSaver
{
    public static class MiniLogger
    {
        private static TextWriterTraceListener _twtl;

        /// <summary>
        /// log message
        /// </summary>
        /// <param name="message"></param>
        [Conditional("DEBUG")]
        public static void LogDebug(String message)
        {
            // if not initialised
            if (_twtl==null)
                Init();

            Trace.WriteLine(string.Format("{0}:{1}:{2} ", DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, message));
        }

        /// <summary>
        /// init file
        /// </summary>
        private static void Init()
        {
            // todo : add checker and if file is larger then set size delete it

            // file name
            string fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Mesopotamia Experiment\ScreenSaver.log";

            // create file logger
            _twtl = new TextWriterTraceListener(fileName);

            // add file logger
            Trace.Listeners.Add(_twtl);

            // set autoflush
            Trace.AutoFlush = true;
        }
    }
}
